﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using CodeCamp12.DAL;
using CodeCamp12.Domain;
using log4net;

namespace CodeCamp12.BLL
{
    public class SessionsBL
    {
        private ILog log = LogManager.GetLogger("CodeCamp12.BLL");

        /// <summary>
        /// Returns all sessions for event
        /// </summary>
        /// <param name="eventNew"></param>
        /// <returns>Session</returns>
        public List<Session> GetSessionForEvent(Event eventNew)
        {
            try 
            {
                var sessionDataProvider = new SessionDataManagament();
                return sessionDataProvider.GetSessionsForEvent(eventNew);
                
            }
            catch(Exception ex)
            {
                log.Error(ex);
                throw;
            }
        }

        /// <summary>
        /// Returns the sessions for the current event
        /// </summary>
        /// <returns></returns>
        public List<Session> GetSessionsForCurrent()
        {
           
            try
            {
                var sessionDataProvider = new SessionDataManagament();
                return sessionDataProvider.GetSessionsForCurrent();
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw;
            }

            
        }

        /// <summary>
        /// Gets all the sessions for speaker with id passed in parametar
        /// </summary>
        /// <param name="id"></param>
        /// <returns>Session</returns>
        public List<Session> GetSessionsForSpeaker(Guid id)
        {
            try
            {
                var sessionDataProvider = new SessionDataManagament();
                return sessionDataProvider.GetSessionsForSpeaker(id);
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw;
            }

          
        }

        /// <summary>
        /// Returns all unused sessions for event
        /// </summary>
        /// <param name="trackId"></param>
        /// <param name="eventId"></param>
        /// <returns>Session</returns>
        public List<Session> GetSessionNotInTrack(Guid trackId, Guid eventId)
        {
            try
            {
                var sessionDataProvider = new SessionDataManagament();
                return sessionDataProvider.GetSessionsNotInTrack(trackId, eventId);
            }
            catch(Exception ex)
            {
                log.Error(ex);
                throw;
            }

        
        }

        /// <summary>
        /// Returns all used sessions for event
        /// </summary>
        /// <param name="trackId"></param>
        /// <param name="eventId"></param>
        /// <returns>Session</returns>
        public List<Session> GetSessionInTrack(Guid trackId, Guid eventId)
        {
            try
            {
                var sessionDataProvider = new SessionDataManagament();
                return sessionDataProvider.GetSessionsInTrack(trackId, eventId);
            }
            catch(Exception ex)
            {
                log.Error(ex);
                throw;
            }
        }

        /// <summary>
        /// Returns all existing sessions for the web site
        /// </summary>
        /// <returns></returns>
        public List<Session> GetAllSessions()
        {
            try
            {
                var sessionDataProvider = new SessionDataManagament();
                return sessionDataProvider.GetAllSessions();
            }
            catch(Exception ex)
            {
                log.Error(ex);
                throw;
            }

            
        }

        /// <summary>
        /// Updates existing session
        /// </summary>
        /// <param name="session"></param>
        public void UpdateSession(Session session)
        {
            var sessionDataProvider = new SessionDataManagament();
            try
            {
                sessionDataProvider.UpdateSession(session);
            }
            catch(Exception ex)
            {
                log.Error(ex);
                throw;
            }

        }
 
        /// <summary>
        /// Deletes session from the website
        /// </summary>
        /// <param name="session"></param>
        public void DeleteSession(Session session)
        {
            
            var sessionDataProvider = new SessionDataManagament();
            try
            {
                sessionDataProvider.DeleteSession(session);
            }
            catch(Exception ex)
            {
                log.Error(ex);
                throw;
            }
        }

        /// <summary>
        /// Removes session from track
        /// </summary>
        /// <param name="sessionId"></param>
        public void DeleteSessionFromTrack(Guid sessionId)
        {
            var sessionDataProvider = new SessionDataManagament();
            try
            {
                sessionDataProvider.DeleteSessionFromTrack(sessionId);
            }
            catch(Exception ex)
            {
                log.Error(ex);
                throw;
            }
        }

        /// <summary>
        /// Inserts new Session
        /// </summary>
        /// <param name="session"></param>
        public string InsertSession(Session session)
        {
            var sessionDataProvider = new SessionDataManagament();
            try
            {
                return sessionDataProvider.InsertSession(session);
            }
            catch(Exception ex)
            {
                log.Error(ex);
                throw;
            }

            

        }
        
        /// <summary>
        /// Returns the session with id as passed in parametar
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public Session GetSessionById(Guid id)
        {
            var sessionDataProvider = new SessionDataManagament();
            try
            {
                return sessionDataProvider.GetSessionById(id);
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw;
            }
            
        }

        /// <summary>
        /// Inserts url to skydrive album for this session
        /// </summary>
        /// <param name="url"></param>
        /// <param name="id"></param>
        public void InsertImagesForSession(string url, Guid id)
        {
            var sessionDataProvider = new SessionDataManagament();
            try
            {
                sessionDataProvider.InsertImagesForSession(url,id);
            }
            catch (Exception ex)
            {
                log.Error(ex);
                throw;
            }
           
        }
    }
}
